import React, { Component } from 'react'

class CounterButton extends Component {
  render() {
    const {onClick} = this.props

    return <button onClick={onClick}>组件+1</button>
  }
}


export default class App extends Component {
  constructor(props) {
    super(props)

    this.state = {
      counter: 0
    }
  }

  render() {
    return (
      <div>
        <h2>当前计数：{this.state.counte}</h2>
        <CounterButton onClick={this.increment.bind(this)} />
        <button onClick={() => this.increment()}>+1</button>
      </div>
    )
  }
  
  increment() {
    console.log("执行increment")
    this.setState({
      counter: this.state.counter + 1
    })
  }
}
